﻿using System;

class MaxIncreasingSequence
{
    static void Main(string[] args)
    {
        //Exercise 5.
        //Write a program that finds the maximal increasing sequence in an array. Example: {3, 2, 3, 4, 2, 2, 4} -> {2, 3, 4}.

        //enter the length and the elements of the array from the console
        Console.Write("Type the length of the array:  ");
        int length = int.Parse(Console.ReadLine());
        Console.WriteLine("Type the elements of the array:");
        int[] array = new int[length];
        for (int i = 0; i < length; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }

        int sequenceLength = 1;        
        int bestSequenceLength = 0;        
        int index = -1;
        int bestIndex = -1;

        for (int i = 0; i < length - 1; i++)
        {
            if (array[i + 1] > array[i])
            {
                sequenceLength++;           //the counter in increased if the following element is bigger than the previous one
                index = i;
                if (sequenceLength > bestSequenceLength)
                {
                    bestSequenceLength = sequenceLength;
                    bestIndex = index - (bestSequenceLength - 2); // returns the index of the first element in the increasing sequence
                }
            }
            else
            {
                sequenceLength = 1;          //else the counter is set at its starting point          
            }
        }
        Console.WriteLine();
        
        Console.Write("Maximal increasing sequence in the array: ");
        for (int i = 0; i < bestSequenceLength; i++)
        {
            Console.Write(array[bestIndex + i] + " ");
        }
        Console.WriteLine();
    }
}

